package pl.edu.agh.iosr.gamblingzone.validators;

import java.util.Calendar;

import pl.edu.agh.iosr.gamblingzone.model.User;

public class UserValidator {

	private static final int matureAge = 21;

	public static boolean isUserMature(User user) {
		boolean result = true;

		Calendar dateOfBirth = Calendar.getInstance();
		dateOfBirth.setTime(user.getBirthDate());

		Calendar today = Calendar.getInstance();
		int age = today.get(Calendar.YEAR) - dateOfBirth.get(Calendar.YEAR);
		dateOfBirth.add(Calendar.YEAR, age);

		if (today.before(dateOfBirth)) {
			age--;
		}

		if (age < matureAge) {
			result = false;
		}

		return result;
	}

	public static boolean isUserNewPwdDifferent(User user, String newPwd) {
		boolean result = true;

		if (user.getPassword().equalsIgnoreCase(newPwd)) {
			result = false;
		}

		return result;
	}

	public static boolean isUserPwdInProperLength(String newPwd) {
		boolean result = true;

		if ((newPwd.length() < 5) || (newPwd.length() > 15)) {
			result = false;
		}

		return result;
	}
}
